package com.huntero.hweather.adapter;

import java.util.ArrayList;
import java.util.List;

import com.huntero.hweather.R;
import com.huntero.hweather.bean.CityCode;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class CityCodeAdapter extends BaseAdapter {

	private List<CityCode> mData=new ArrayList<CityCode>();
	private Context mContext;
	private LayoutInflater mInflater;
	
	public CityCodeAdapter(Context context,List<CityCode> data){
		this.mContext = context;
		this.mData = data;
		this.mInflater = LayoutInflater.from(context);
	}
	
	@Override
	public int getCount() {
		return this.mData.size();
	}

	@Override
	public Object getItem(int position) {
		if(this.mData == null || this.mData.size() <= position)
			return null;
		return this.mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Item item = null;
		if(convertView == null){
			convertView = this.mInflater.inflate(R.layout.item_in_spinner_dialog, null);
			item = new Item();
			item.value = (TextView) convertView.findViewById(R.id.item_value);
			item.chk = (CheckBox) convertView.findViewById(R.id.item_chk);
			
			convertView.setTag(item);
		}else{
			item = (Item) convertView.getTag();
		}
		item.value.setText(this.mData.get(position).cnName);
		return convertView;
	}
	public List<CityCode> getListData(){
		return this.mData;
	}
	
	static class Item{
		public TextView value;
		public CheckBox chk;
	}
}
